# 定义一个 3x3 的矩阵
matrix = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]


def t1():
    # 使用嵌套列表推导式进行矩阵转置
    transposed_matrix = [[row[i] for row in matrix] for i in range(3)]
    print(transposed_matrix)


# 使用非推导式实现矩阵转置
def transpose_matrix(matrix):
    # 初始化转置后的矩阵
    transposed_matrix = []
    # 遍历原矩阵的列索引
    for i in range(len(matrix[0])):
        # 提取每一列的元素并作为新行添加到转置矩阵中
        new_row = []
        for row in matrix:
            new_row.append(row[i])
        transposed_matrix.append(new_row)
    return transposed_matrix


# 调用函数并打印结果
print(transpose_matrix(matrix))

squares = [x ** 2 for x in range(10)]
print("squares", squares)


def add(x):
    print("x", x)
    return x + 1


a = [add(x) for x in range(10)]
print("a", a)
